//
//  OtherViewController.m
//  ProfilePicture
//
//  Created by 张云江 on 2019/10/14.
//  Copyright © 2019年 张云江. All rights reserved.
//

#import "OtherViewController.h"
#import "HomeCollectionViewCell.h"

static NSString *cellId = @"Other_Identifier";

@interface OtherViewController () <UICollectionViewDelegate,UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView  *ordinaryCollectionView;
@property (nonatomic, strong) NSMutableArray    *headArray;

@end

@implementation OtherViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)creatUI
{
    self.customNavBar.hidden = YES;
    self.headArray = [NSMutableArray array];
    
    HomeInfoMode *info = [[HomeInfoMode alloc] init];
    [info setSizeW:307 withSizeH:377 withName:@"身份证" withSizeDes:@"307 x 377 px" withSpecId:184];
    [self.headArray addObject:info];
    HomeInfoMode *info1 = [[HomeInfoMode alloc] init];
    [info1 setSizeW:307 withSizeH:377 withName:@"居住证" withSizeDes:@"307 x 377 px" withSpecId:655];
    [self.headArray addObject:info1];
    HomeInfoMode *info2 = [[HomeInfoMode alloc] init];
    [info2 setSizeW:358 withSizeH:441 withName:@"社保卡" withSizeDes:@"358 x 441 px" withSpecId:362];
    [self.headArray addObject:info2];
    HomeInfoMode *info3 = [[HomeInfoMode alloc] init];
    [info3 setSizeW:259 withSizeH:377 withName:@"驾驶证,驾照" withSizeDes:@"259 x 377 px" withSpecId:183];
    [self.headArray addObject:info3];
    HomeInfoMode *info4 = [[HomeInfoMode alloc] init];
    [info4 setSizeW:295 withSizeH:413 withName:@"简历照片" withSizeDes:@"295 x 413 px" withSpecId:391];
    [self.headArray addObject:info4];
    HomeInfoMode *info5 = [[HomeInfoMode alloc] init];
    [info5 setSizeW:358 withSizeH:441 withName:@"医保证" withSizeDes:@"358 x 441 px" withSpecId:282];
    [self.headArray addObject:info5];
    HomeInfoMode *info6 = [[HomeInfoMode alloc] init];
    [info6 setSizeW:295 withSizeH:413 withName:@"健康证" withSizeDes:@"295 x 413 px" withSpecId:178];
    [self.headArray addObject:info6];
    HomeInfoMode *info7 = [[HomeInfoMode alloc] init];
    [info7 setSizeW:265 withSizeH:351 withName:@"执法证" withSizeDes:@"265 x 351 px" withSpecId:189];
    [self.headArray addObject:info7];
    HomeInfoMode *info8 = [[HomeInfoMode alloc] init];
    [info8 setSizeW:240 withSizeH:320 withName:@"校园卡" withSizeDes:@"240 x 320 px" withSpecId:241];
    [self.headArray addObject:info8];
    HomeInfoMode *info9 = [[HomeInfoMode alloc] init];
    [info9 setSizeW:252 withSizeH:312 withName:@"社保卡" withSizeDes:@"252 x 312 px" withSpecId:362];
    [self.headArray addObject:info9];
    HomeInfoMode *info10 = [[HomeInfoMode alloc] init];
    [info10 setSizeW:480 withSizeH:640 withName:@"学籍网" withSizeDes:@"480 x 640 px" withSpecId:254];
    [self.headArray addObject:info10];
    HomeInfoMode *info11 = [[HomeInfoMode alloc] init];
    [info11 setSizeW:390 withSizeH:567 withName:@"在职研究生考试" withSizeDes:@"390 x 567 px" withSpecId:227];
    [self.headArray addObject:info11];
    HomeInfoMode *info12 = [[HomeInfoMode alloc] init];
    [info12 setSizeW:390 withSizeH:567 withName:@"执业医师资格证" withSizeDes:@"390 x 567 px" withSpecId:159];
    [self.headArray addObject:info12];
    HomeInfoMode *info13 = [[HomeInfoMode alloc] init];
    [info13 setSizeW:413 withSizeH:531 withName:@"入台证" withSizeDes:@"413 x 531 px" withSpecId:577];
    [self.headArray addObject:info13];
    
    self.view.backgroundColor = kUIColorFromRGB(0xF3F5FF);
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.minimumInteritemSpacing = kRatio(2);
    layout.minimumLineSpacing = kRatio(20);
    layout.footerReferenceSize = CGSizeMake(kScreenWidth, kRatio(40));
    CGFloat itemW = (kScreenWidth - kRatio(80))/2;
    CGFloat itemH = itemW;
    
    layout.itemSize = CGSizeMake(itemW, itemH);
    
    self.ordinaryCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(kRatio(30), 0, self.view.frame.size.width - kRatio(60), kScreenHeight - kRatio(260)) collectionViewLayout:layout];
    [self.ordinaryCollectionView registerClass:[UICollectionView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeadCollectionView"];
    [self.ordinaryCollectionView registerClass:[HomeCollectionViewCell class] forCellWithReuseIdentifier:cellId];
    self.ordinaryCollectionView.backgroundColor = [UIColor clearColor];
    self.ordinaryCollectionView.showsVerticalScrollIndicator = NO;
    self.ordinaryCollectionView.delegate = self;
    self.ordinaryCollectionView.dataSource = self;
    
    [self.view addSubview:self.ordinaryCollectionView];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView
     numberOfItemsInSection:(NSInteger)section
{
    return self.headArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                  cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HomeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellId
                                                                             forIndexPath:indexPath];
    HomeInfoMode *info = self.headArray[indexPath.row];
    [cell updateInfo:info];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    HomeInfoMode *info = self.headArray[indexPath.row];
    self.onCellClick(info);
}
@end
